package com.chen.webservice.Utils;

import com.chen.webservice.model.Order;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.chen.webservice.Utils.RuleConstants.OrderType.BUSINESS;

/**
 * @description: 规则102 同品类商业节目不能相邻
 * @params:
 * @return:
 * @author: chenzhiwen
 * @dateTime: 2021/10/21 下午7:16
 */
@Service
public class Weak102Handler implements RuleHandler {
    private static final int factor = 1;//系数
    private static final int ruleNum = 102;

    @Override
    public int ruleNum() {
        return this.ruleNum;
    }

    @Override
    public boolean isMatch(List<Integer> rules) {
        return rules.contains(ruleNum);//强校验
    }

    @Override
    public int checkResult(List<Order> orders, int rate) {
        rate = 0;
        int len = orders.size();
        if (len <= 1) {
            return rate;
        }
        for (int i = 0; i < len - 1; i++) {
            Order o1 = orders.get(i);
            Order o2 = orders.get(i + 1);
            if (o1.getCategory() == BUSINESS.getValue()
                    && o2.getCategory() == BUSINESS.getValue()
                    && o1.getCategorySub() == o2.getCategorySub()) {
                rate += 1;
            }//0
        }

        return rate * factor;
    }
}
